	/*
	* @Author: zlx
	* @Date:   2018-02-27 10:08:24
	* @Last Modified by:   zlx
	* @Last Modified time: 2018-02-27 11:21:03
	*/
var password='',panter=/^1[34578][0-9]{9}$/,time=60,smsCode;
$(function(){
	//无账号去注册
	//有账号直接登陆
	$(document).on('click','.color',function(){
		window.location.href='zhuce.html';
	})
	//账号密码登陆
	$(document).on('click','.zm_deng',function(){
		window.location.href='login_zm.html';
	})

	//短信验证码登陆
	$(document).on('click','.toLogin .left',function(){
		window.location.href='login.html';
	})

	//忘记密码
	$(document).on('click','.toLogin .right',function(){
		window.location.href='forget.html';
	})
	//qq登陆
	$('#qq').on('click',function(){
		window.location.href='../singlecenter/login_san.html?1';
	})
	//微信登陆
	$('#wx').on('click',function(){
//		window.location.href=rootdomain+'html/singlecenter/login_san.html?2';
		tips('暂不支持微信登录')
	})
	//密码明文非明文切换
	$(document).on('click','.eye',function(){
//		alert(1)
	    if($(this).find('img').attr("src") == "../../img/a_eye.png"){
	            $(".yzm .zz").prop("type","text");
	            $(this).find('img').attr("src","../../img/a_eye2.png");
	    }else{
	            $(".yzm .zz").prop("type","password");
	            $(this).find('img').attr("src","../../img/a_eye.png");
	    }
	});
	$(document).on('click','.send',function(){
		//获取验证码
		if($(this).attr('id')){
			type=$(this).attr('type');
			if(!panter.test($('.phone_n').val())){
				tips('请输入正确的手机号');
				return false;
			}else if(!$('.phone_n').val()){
				tips('请先填写手机号');
				return false;
			}else{
				$.post(apicom+'mobile/view/member/sendSms',{
					phone:$('.phone_n').val(),
					type:1//登陆
				},function(res){
//					res=JSON.parse(res)
					setTimeout(function(){
						tips(res.msg)
					},1000);
					$('.send').attr('id','');
	                $('.send').text("重新获取" + "(" + (time) + ")");
	                var setId = setInterval(function() {
	                    if (time <= 0) {
	                        $('.send').attr('id','send');
	                        $('.send').text("发送验证码");
	                        clearInterval(setId);
	                        time=60;
	                    } else {
	                        time--;
	                        $('.send').text("重新获取" + "(" + (time) + ")");
	                    }
	                }, 1000);
				})
			}
		}
	})
	//登陆
	$(document).on('click','.login',function(){
		loginType=Number($(this).attr('type'));
		phone=$('.phone_n').val();
		if(''==phone){
			tips('请先填写手机号');
			return false;
		}
		if(!panter.test(phone)){
			tips('手机号码格式不正确');
			return false;
		}
		if(1==loginType){
			password=$('.yan_m').val();
			if(''==password){
				tips('请输入密码');
				return false;
			}
		}else{
			smsCode=$('.yan_m').val();
			if(''==smsCode){
				tips('请输入验证码');
				return false;
			}
		}
		$.post(apicom+'mobile/view/member/member-login',{
			phone:phone,
			password:password,
			loginType:loginType,
			smsCode:smsCode,
			mark:mark
		},function(res){
			if(typeof res == "string"){
	            res=JSON.parse(res);
	        }
			tips(res.msg)
			if(1==res.code){
				localStorage.setItem('user_info',JSON.stringify(res));
				var url_his='../homePage/sy.html'
				if(sessionStorage.getItem('history_url')){
					url_his=sessionStorage.getItem('history_url')
				}
				setTimeout(function(){
					sessionStorage.removeItem('history_url')
					window.location.href=url_his;
				},1000)
			}
		})
	})
})
